package com.blog.controller;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description: 测试
 * @Author: 刘会俊
 * @Date: 2019-03-27 22:54
 */
public class StringNullAdpater extends TypeAdapter<String> {


    @Override
    public String read(JsonReader reader) throws IOException {
        // TODO Auto-generated method stub
        if (reader.peek() == JsonToken.NULL) {
            reader.nextNull();
            return "";
        }
        return reader.nextString();
    }
    @Override
    public void write(JsonWriter writer, String value) throws IOException {
        // TODO Auto-generated method stub
        if (value == null) {
            writer.value("");
            return;
        }
        writer.value(value);
    }

    public static void main(String[] args) throws NoSuchAlgorithmException, ParseException {
        String str = "2012-01-30";
        String str1 = "2012-01-31";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = simpleDateFormat.parse(str);
        Date date2 = simpleDateFormat.parse(str1);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date1);
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date2);
        calendar.add(Calendar.MONTH, 1);
        calendar1.add(Calendar.MONTH, 1);
        System.out.println(simpleDateFormat.format(calendar.getTime()));
        System.out.println(simpleDateFormat.format(calendar1.getTime()));
    }
}
